package classes;
import java.io.PrintStream;

public final class Func {
	
	public static final String padStr(int size, char C) {
		String	S = "";
		int		i;
		for(i=0;i<size;i++)
			S = S + C;
		return S;
	}
	public static final String padStr(int size) {
		return padStr(size,' ');
	}
	public static final String fstring(String S, int size) {
		return fstring(S,size,true,' ');
	}
	public static final String fstring(String S, int size, boolean padRight, char fill) {
		if (S.length() >= size) {
			return S.substring(0,size);
		} else if (!padRight) {
			return padStr(size-S.length(),fill) + S;
		} else {
			return S + padStr(size-S.length(),fill);
		}
	}

	private static int indent = 0;
	private static int indentSize = 4;

	public static final void fwdP(String S) {
		fwdP(S,System.out);
	}
	public static final void fwdP(String S, PrintStream O) {
		midP(S,O);
		indent ++;
	}
	public static final void endP(String S) {
		endP(S,System.out);
	}
	public static final void endP(String S, PrintStream O) {
		indent--;
		if (indent<0) indent = 0;
		midP(S);
	}
	public static final void midP(String S) {
		midP(S,System.out);
	}
	public static final void midP(String S, PrintStream O) {
		System.out.print(padStr(indent*indentSize) + S);
	}
	
	public static final boolean equals(Object A, Object B) {
		if (A==null) {
			return (B==null);
		} else {
			return (B!=null) && A.equals(B);
		}
	}
	public static final String str(Object O) {
		if (O==null) {
			return "null";
		} else {
			return O.toString();
		}
	}

}
